import 'package:boss/models/staff.dart';
import 'package:boss/textStyle/text_style.dart';
import 'package:boss/ui/widget/shadow_radius_card.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';
import 'dart:math';

class StaffItem extends StatelessWidget {
  final VoidCallback onTap;
  final Staff data;

  const StaffItem({
    Key key,
    this.onTap,
    this.data,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    int days;

    if (data.ctime != null) {
      var now = DateTime.now();
      var ctime = DateTime.parse(data.ctime);
      days = now.difference(ctime).inDays;
    }

    return GestureDetector(
      onTap: onTap,
      behavior: HitTestBehavior.translucent,
      child: ShadowRadiusCard(
        margin: EdgeInsets.only(top: 30.w),
        padding: EdgeInsets.only(left: 30.w, right: 20.w, top: 25.w, bottom: 25.w),
        child: DefaultTextStyle(
          style: TextStyle(height: 1),
          child: Stack(
            overflow: Overflow.visible,
            children: <Widget>[
              Container(
                margin: EdgeInsets.only(top: 25.w),
                child: Row(
                  children: <Widget>[
                    Expanded(
                      child: Text('${data.realname}', style: TextStyleConstant().normal_1_32),
                    ),
                    Expanded(
                      child: Text('${data.username}', style: TextStyleConstant().normal_2_26),
                    ),
                    Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                        Text('${days == null ? '--' : max(1, days)}', style: TextStyleConstant().normal_1_26),
                        Container(
                          margin: EdgeInsets.only(top: 20.w),
                          child: Text(
                            '在职天数',
                            style: TextStyleConstant().normal_4_24,
                          ),
                        ),
                      ],
                    ),
                  ],
                ),
              ),
              if (data.roleName != null)
                Positioned(
                  top: -15.w,
                  left: -42.w,
                  child: Container(
                    height: 42.w,
                    alignment: Alignment.center,
                    padding: EdgeInsets.only(left: 10.w, bottom: 4.w, right: 10.w),
                    decoration: BoxDecoration(
                      image: DecorationImage(image: ExactAssetImage('assets/image/staff_badge1.png'), fit: BoxFit.fill),
                    ),
                    child: Text(data.roleName, style: TextStyleConstant().white_20.copyWith(height: 1)),
                  ),
                ),
            ],
          ),
        ),
      ),
    );
  }
}
